<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{$config_sitename}</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="__CSS__/login.css?t={$ver}" rel="stylesheet">
</head>
<body>
	<div class="login-wrapper">
        <div class="login-top ub ub-ver ub-ac cl-b-orange">
            <img class="login-logo" src="__IMAGES__/logo.png" alt="">
            <p class="cl-f-white">中国烘焙第一门户网 专业的烘焙学习分享平台</p>
        </div>
        <form class="login-info ub ub-ver ub-ac ub-pc cl-f-dgrey">
            <p><label class="f16" for="login-email">账号：</label><input id="login-email" type="text" name="uname" class="login-input" placeholder="输入正确邮箱"></p>
            <p><label class="f16" for="login-psw">密码：</label><input id="login-psw" type="password" name="password" class="login-input"></p>
            <p class="yf-pass" style="display: none;"><label class="f16" for="login-psw2">确认密码：</label><input id="login-psw2" type="password" name="password2" class="login-input"></p>
            <p><a class="btn-login cl-b-orange cl-f-white" href="javascript:;" data-type="yes" data-status="1">立即绑定</a></p>
        </form>
        <div class="login-tips cl-b-lgrey">
            <p>温馨提示：</p>
            <p>1、已有pc端账号，请输入你pc端的账号密码。</p>
            <p>2、还没有pc端账号，请输入新的账号(邮箱)以及密码，该账号将可以用于pc端登录。</p>
            <p>3、每个账号只有一次绑定机会。</p>
        </div>
    </div>
	<script src="__JS__/jquery-1.11.1.min.js?t={$ver}"></script>
    <script src="__JS__/common.js?t={$ver}"></script>
    <script>
        function warn(msg,opt,left,top){
            if (opt){
                 var obj = $('#'+opt);
            }
            new Toast({context:$('body'),message:msg},obj,left,top).show();
        }

        $(document).ready(function(){
            $('#login-email').blur(function(e){
                var uname = $(this).val();
                if(uname == '' || uname == null || uname == undefined)
                {
                    showToast('账号不能为空');
                    return false;
                }
                $.ajax({
                    url: "{:U('Login/checkname')}",
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        uname: uname
                    },
                    success: function(res){
                        showToast(res.info);
                    	$('input[name=password]').val('');
                        if(res.status == 1)
                        {
                        	$('.yf-pass').hide();
                        	$('.btn-login').attr('data-status', 1);
                        }
                        else
                        {
                            $('.yf-pass').show();
                        	$('.btn-login').attr('data-status', 0);
                        }
                    }
                });
            });
            
            $('.btn-login').click(function(e){
                /*var email = $('#login-email').val(),psw = $('#login-psw').val(),psw2 = $('#login-psw2').val();
                var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                if( email == '' || psw == '' || psw2 == '') {
                    warn('内容为空','','','');
                }else if(!reg.test(email)) {
                    warn('邮箱格式不对','','','');
                }else if(psw != psw2) {
                    warn('密码不一致','','','');
                }*/
                e.preventDefault();
                var _this = $(this);
                var type = _this.attr('data-type');
                if(type == 'yes')
                {
                    var status = _this.attr('data-status');
                    var uname = $('input[name=uname]').val();
                    if(uname == '' || uname == null || uname == undefined)
                    {
                        showToast('请输入账号');
                        return false;
                    }
                    var password = $('input[name=password]').val();
                    if(password == '' || uname == null || uname == undefined)
                    {
                        showToast('请输入密码');
                        return false;
                    }
                    var act = 'doLogin';
                    if(status == 0)
                    {
                        var password2 = $('input[name=password2]').val();
                    	if(password2 == '' || password2 == null || password2 == undefined)
                        {
                            showToast('请输入确认密码');
                            return false;
                        }
                        act = 'doReg';
                    }
                    _this.attr('data-type', 'no');
                    $.ajax({
                        url: "{:U('Login/" + act + "')}",
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            uname: uname,
                            password: password,
                            password2: password2
                        },
                        success: function(res){
                            _this.attr('data-type', 'yes');
                            showToast(res.info);
                            setTimeout(function(){
                                if(res.url != '' && res.url != null && res.url != undefined)
                                {
                                    location.href = res.url;
                                }
                            }, 1000);
                        },
                        error: function(res){
                        	_this.attr('data-type', 'yes');
                        }
                    });
                }
                else
                {
                    showToast('验证信息中,请稍候');
                }
            })
        })
    </script>
</body>
</html>